export async function SHA256(str: string): Promise<string>  {
	const encoder = new TextEncoder();
	const data = encoder.encode(str);
	const hash = await crypto.subtle.digest('SHA-256', data);
	const hashArray = Array.from(new Uint8Array(hash));
	return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}

export async function hashPassword(password: string, salt: string): Promise<string> {
	return SHA256(`${password}${salt}`);
}

export async function verifyPassword(hash: string, password: string, salt: string): Promise<boolean> {
	return hash === await hashPassword(password, salt);
}
